﻿using AutoMapper;
using B.S.DataBase.SuY.Read.Api.AutoList.Command;
using B.S.DataBase.SuYuan.Domain.Model;
using B.S.DataBase.SuYuan.ErrorCode;
using B.S.DataBase.SuYuan.Infrastructrue.Interface;
using MediatR;

namespace B.S.DataBase.SuY.Read.Api.AutoList.CommandHarder
{
    public class DelListGoodsCommandHarder : IRequestHandler<DelListGoodsCommand, ApiReslit<object>>
    {

        private readonly IMapper mapper;
        private readonly IBaseRepository<Goods> repository;

        public DelListGoodsCommandHarder(IMapper mapper, IBaseRepository<Goods> repository)
        {
            this.mapper = mapper;
            this.repository = repository;
        }

        public Task<ApiReslit<object>> Handle(DelListGoodsCommand request, CancellationToken cancellationToken)
        {
            ApiReslit<object> reslit = new ApiReslit<object>();
            var obj = request.G_Id.Select(x=>new Goods {G_Id=x}).ToList();
            var res= repository.DeleteRemove(obj).Result;
            if (res>0)
            {
                reslit.Code = ApiEnum.删除成功;
                reslit.Msg = ApiEnum.删除成功.ToString();
            }
            else {
                reslit.Code = ApiEnum.删除失败;
                reslit.Msg = ApiEnum.删除失败.ToString();
            }
            

       

            return Task.FromResult(reslit);
        }
    }
}
